package com.oocl.o2o.merchant.controller.rest;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttribute;

import com.oocl.o2o.merchant.entity.Merchant;
import com.oocl.o2o.merchant.entity.OrderInfo;
import com.oocl.o2o.merchant.service.OrderInfoManager;

@RestController
@RequestMapping("/sec/rest/orderInfo")
public class OrderInfoController {

	@Autowired
	private OrderInfoManager orderInfoManager;

	@GetMapping
	public List<OrderInfo> getMyOrderInfos(@SessionAttribute String merchantId) {
		List<OrderInfo> orderInfos = orderInfoManager.findByMerchantId(merchantId);
		return orderInfos;
	}

	@GetMapping("/{orderInfoId}/{orderStatus}")
	public OrderInfo updateOrderInfo(@PathVariable("orderInfoId")String orderInfoId, 
			@PathVariable("orderStatus")String orderStatus) {
		OrderInfo orderInfo = null;
		switch (orderStatus) {
		case "RECEIVE":
			orderInfo = orderInfoManager.acceptOrder(orderInfoId);
			break;
		case "DELIVERING":
			orderInfo = orderInfoManager.deliveryOrder(orderInfoId);
			break;
		case "REJECT":
			orderInfo = orderInfoManager.refuseOrder(orderInfoId);
			break;
		}
		return orderInfo;
	}

}
